﻿using DotNetCommon.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebUserTest.Controller
{
    [Route("api/[controller]/[action]")]
    public class HomeController : ControllerBase
    {
        private readonly ILogger<HomeController> logger;

        public HomeController(ILogger<HomeController> logger)
        {
            this.logger = logger;
        }

        [HttpGet]
        public async Task<string> Get(string name, int age)
        {
            var id = DotNetCommon.User.Current.IdString;
            var isAuthenticated = DotNetCommon.User.Current.IsAuthenticated;
            DotNetCommon.User.Current.SetProperty("name", name + "2");
            DotNetCommon.User.Current.SetProperty("age", age);
            var str = $"{id}-{isAuthenticated}";
            await Task.Run(() =>
            {
                var name = DotNetCommon.User.Current.GetProperty("name");
                var age = DotNetCommon.User.Current.GetProperty("age");
                str += $"-name:{name}-age:{age}";
            });
            return str;
        }
    }
}
